﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MossmanMill.DataModel;

namespace MossmanMill
{

    public enum DrawType
    {
        Icon,
        Full
    }

    public abstract class Slottable : IDrawable
    {
        public int SlotId { get; protected internal set; } //Slot_Id
        public int RackId { get; protected internal set; } //Rack_Id
        public int Position { get; protected internal set; } //Slot_Position
        public char SlotType { get; protected internal set; } //Slot_Type

        private Rack _rack;
        public Rack Rack
        {
            get {
                if (_rack != null) return _rack;
                var db = DatabaseAccess.Instance;
                _rack = db.GetRack(RackId);
                return _rack;
            }
        }

        public abstract string[] GetInfo();


        public virtual void Release()
        {
            _rack = null;
        }

        abstract public bool interact(System.Drawing.Point location, int type, int x, int y, float scale = 1.0f, bool interactWithChildren = false);
        abstract public System.Drawing.Bitmap GetDrawBitmap(System.Drawing.Rectangle bounds, DrawType type);
        abstract public void draw(System.Drawing.Graphics g, int x, int y, float scale = 1.0f, bool drawChildren = false);
        abstract public void draw(System.Drawing.Graphics g, System.Drawing.Rectangle bounds, float scale = 1.0f, bool drawChildren = false);

        public bool Equals(Slottable card)
        {
            bool equal = card.Position == Position &&
                card.SlotType == SlotType &&
                card.RackId == RackId;
            if (!equal)
            {
                Console.WriteLine(card.Position + " - " + Position);
                Console.WriteLine(card.SlotType + " - " + SlotType);
                Console.WriteLine(card.RackId   + " - " + RackId);
            }
            return equal;
        }
    }
}
